/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIPrincipal.java
 *
 * Created on 15/02/2011, 18:36:27
 */
package br.com.geradormvc.visao.gui;

import br.com.geradormvc.excessao.GeradorMVCException;
import br.com.geradormvc.modelo.dominio.Principal;
import br.com.geradormvc.modelo.dominio.Tabela;
import br.com.geradormvc.persistencia.impl.ParametrosDB;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author douglas
 */
public class GUIPrincipal extends javax.swing.JFrame {

    /** Creates new form GUIPrincipal */
    public GUIPrincipal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlBotoes = new javax.swing.JPanel();
        btnFinalizar = new javax.swing.JButton();
        btnAjuda = new javax.swing.JButton();
        btnProximo = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        pnlImagem = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        pnlPrincipal = new javax.swing.JPanel();
        pnlPasso1 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        lblArquivoDeConfiguracao = new javax.swing.JLabel();
        edtArquivoDeConfiguracao = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        divTop = new javax.swing.JSeparator();
        lblURL = new javax.swing.JLabel();
        edtURL = new javax.swing.JTextField();
        lblPassword = new javax.swing.JLabel();
        edtSenha = new javax.swing.JPasswordField();
        divButton = new javax.swing.JSeparator();
        lblDataBase = new javax.swing.JLabel();
        cbDatabase = new javax.swing.JComboBox();
        btnConectarDatabase = new javax.swing.JButton();
        lblDriver = new javax.swing.JLabel();
        cbDriver = new javax.swing.JComboBox();
        lblUsuario = new javax.swing.JLabel();
        edtUsuario = new javax.swing.JTextField();
        btnTestarConexao = new javax.swing.JButton();
        btnLimparDados = new javax.swing.JButton();
        pnlPasso2 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblTabelas = new javax.swing.JLabel();
        cbTabelas = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblColunasTabela = new javax.swing.JTable();
        btnListarCampos = new javax.swing.JButton();
        pnlPasso3 = new javax.swing.JPanel();
        lblNomeDaClasse = new javax.swing.JLabel();
        edtNomeDaClasse = new javax.swing.JTextField();
        lblNomeDoProjeto = new javax.swing.JLabel();
        edtNomeDoProjeto = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblColunasSelecionadas = new javax.swing.JTable();
        pnlPasso4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnFinalizar.setText("Finalizar");
        btnFinalizar.setPreferredSize(new java.awt.Dimension(92, 27));
        btnFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFinalizarActionPerformed(evt);
            }
        });

        btnAjuda.setText("Ajuda");
        btnAjuda.setPreferredSize(new java.awt.Dimension(92, 27));

        btnProximo.setText("Próximo >");
        btnProximo.setPreferredSize(new java.awt.Dimension(92, 27));
        btnProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProximoActionPerformed(evt);
            }
        });

        btnAnterior.setText("< Anterior");
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.setPreferredSize(new java.awt.Dimension(92, 27));
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBotoesLayout = new javax.swing.GroupLayout(pnlBotoes);
        pnlBotoes.setLayout(pnlBotoesLayout);
        pnlBotoesLayout.setHorizontalGroup(
            pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotoesLayout.createSequentialGroup()
                .addContainerGap(243, Short.MAX_VALUE)
                .addComponent(btnAnterior)
                .addGap(18, 18, 18)
                .addComponent(btnProximo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnFinalizar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAjuda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlBotoesLayout.setVerticalGroup(
            pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotoesLayout.createSequentialGroup()
                .addContainerGap(16, Short.MAX_VALUE)
                .addGroup(pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAjuda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnFinalizar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnProximo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAnterior))
                .addContainerGap())
        );

        getContentPane().add(pnlBotoes, java.awt.BorderLayout.PAGE_END);

        pnlImagem.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 12));
        jLabel1.setText("Passos");

        jLabel2.setIcon(new javax.swing.ImageIcon("/home/douglas/Download/http:__iconesbr.oficinadanet.com_7575_128x128.png")); // NOI18N

        javax.swing.GroupLayout pnlImagemLayout = new javax.swing.GroupLayout(pnlImagem);
        pnlImagem.setLayout(pnlImagemLayout);
        pnlImagemLayout.setHorizontalGroup(
            pnlImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlImagemLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pnlImagemLayout.setVerticalGroup(
            pnlImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlImagemLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(177, Short.MAX_VALUE))
        );

        getContentPane().add(pnlImagem, java.awt.BorderLayout.WEST);

        pnlPrincipal.setLayout(new java.awt.CardLayout());

        pnlPasso1.setVerifyInputWhenFocusTarget(false);
        pnlPasso1.setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados da Conexão"));

        lblArquivoDeConfiguracao.setText("Arquivo de Configuração");

        edtArquivoDeConfiguracao.setEnabled(false);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/geradormvc/icones/icoImportar.png"))); // NOI18N
        jButton1.setEnabled(false);

        lblURL.setText("URL");

        edtURL.setText("jdbc:postgresql://localhost:5432");

        lblPassword.setText("Senha");

        lblDataBase.setText("Databases");

        cbDatabase.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione uma Database..." }));
        cbDatabase.setEnabled(false);

        btnConectarDatabase.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/geradormvc/icones/icoExecutar.png"))); // NOI18N
        btnConectarDatabase.setText("Conectar Database");
        btnConectarDatabase.setEnabled(false);

        lblDriver.setText("Driver");

        cbDriver.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "org.postgresql.Driver" }));

        lblUsuario.setText("Usuário");

        edtUsuario.setText("postgres");

        btnTestarConexao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/geradormvc/icones/icoExecutar.png"))); // NOI18N
        btnTestarConexao.setText("Testar Conexão");

        btnLimparDados.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/geradormvc/icones/icoRefresh.png"))); // NOI18N
        btnLimparDados.setText("Limpar Dados");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(divTop, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblDriver)
                        .addContainerGap(571, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lblDataBase)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbDatabase, 0, 345, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnConectarDatabase))
                            .addComponent(divButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lblArquivoDeConfiguracao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(edtArquivoDeConfiguracao, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblURL)
                                    .addComponent(lblUsuario))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(edtURL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(edtUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblPassword)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(edtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(btnTestarConexao, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnLimparDados, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(cbDriver, javax.swing.GroupLayout.Alignment.LEADING, 0, 547, Short.MAX_VALUE))))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblArquivoDeConfiguracao)
                    .addComponent(edtArquivoDeConfiguracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(divTop, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDriver)
                    .addComponent(cbDriver, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblURL)
                    .addComponent(edtURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(edtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPassword)
                    .addComponent(lblUsuario)
                    .addComponent(edtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLimparDados)
                    .addComponent(btnTestarConexao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(divButton, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDataBase)
                    .addComponent(btnConectarDatabase)
                    .addComponent(cbDatabase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );

        pnlPasso1.add(jPanel1, java.awt.BorderLayout.CENTER);

        pnlPrincipal.add(pnlPasso1, "passo1");

        pnlPasso2.setLayout(new java.awt.BorderLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados da Tabela"));

        lblTabelas.setText("Selecione a Tabela");

        cbTabelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Selecione os campos desejados"));
        jPanel3.setLayout(new java.awt.BorderLayout());

        tblColunasTabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Selecionar", "Tipo Objeto", "Nome Coluna", "Tipo Coluna", "Nulo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblColunasTabela);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        btnListarCampos.setText("Listar Campos");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(lblTabelas)
                        .addGap(18, 18, 18)
                        .addComponent(cbTabelas, 0, 342, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnListarCampos))
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTabelas)
                    .addComponent(cbTabelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnListarCampos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                .addContainerGap())
        );

        pnlPasso2.add(jPanel2, java.awt.BorderLayout.CENTER);

        pnlPrincipal.add(pnlPasso2, "card3");

        pnlPasso3.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados da Classe"));

        lblNomeDaClasse.setText("Nome da Classe");

        lblNomeDoProjeto.setText("Nome do Projeto");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Edição dos Campos da Classe"));
        jPanel4.setLayout(new java.awt.BorderLayout());

        tblColunasSelecionadas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tipo Obj", "Nome Coluna", "Tipo Coluna", "Nome Atributo", "Tipo Atributo", "Inserir", "Alterar"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tblColunasSelecionadas);

        jPanel4.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout pnlPasso3Layout = new javax.swing.GroupLayout(pnlPasso3);
        pnlPasso3.setLayout(pnlPasso3Layout);
        pnlPasso3Layout.setHorizontalGroup(
            pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPasso3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
                    .addGroup(pnlPasso3Layout.createSequentialGroup()
                        .addGroup(pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlPasso3Layout.createSequentialGroup()
                                .addComponent(lblNomeDaClasse)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(edtNomeDaClasse, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE))
                            .addGroup(pnlPasso3Layout.createSequentialGroup()
                                .addComponent(lblNomeDoProjeto)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(edtNomeDoProjeto, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        pnlPasso3Layout.setVerticalGroup(
            pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPasso3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNomeDaClasse)
                    .addComponent(edtNomeDaClasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlPasso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNomeDoProjeto)
                    .addComponent(edtNomeDoProjeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                .addContainerGap())
        );

        pnlPrincipal.add(pnlPasso3, "card4");

        pnlPasso4.setBorder(javax.swing.BorderFactory.createTitledBorder("Log de Criação das Classes"));
        pnlPasso4.setLayout(new java.awt.BorderLayout());

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane4.setViewportView(jTextArea1);

        pnlPasso4.add(jScrollPane4, java.awt.BorderLayout.CENTER);

        pnlPrincipal.add(pnlPasso4, "card5");

        getContentPane().add(pnlPrincipal, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProximoActionPerformed
        // TODO add your handling code here:
        CardLayout cl = (CardLayout) (pnlPrincipal.getLayout());
        cl.next(pnlPrincipal);
        exibirColunasSelecionadas();

    }//GEN-LAST:event_btnProximoActionPerformed

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        // TODO add your handling code here
        CardLayout cl = (CardLayout) (pnlPrincipal.getLayout());
        cl.previous(pnlPrincipal);
    }//GEN-LAST:event_btnAnteriorActionPerformed

    private void btnFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalizarActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_btnFinalizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public void exibirMensagem(String mensagem, String titulo, boolean isErro) {
        int tipo;

        if (isErro) {
            tipo = JOptionPane.ERROR_MESSAGE;
        } else {
            tipo = JOptionPane.INFORMATION_MESSAGE;
        }
        JOptionPane.showMessageDialog(null, mensagem, titulo, tipo);
    }

    public void exibirDatabases(List databases) throws GeradorMVCException {
        try {
            this.databases = databases;
            int i = 0;
            Iterator resultado = databases.iterator();
            System.out.print("chegou aqui");
            this.cbDatabase.removeAllItems();
            while (resultado.hasNext()) {
                this.cbDatabase.addItem(databases.get(i));
                resultado.next();
                i++;
                System.out.print("chegou aqui tamém");
            }
        } finally {
            cbDatabase.setEnabled(true);
            btnConectarDatabase.setEnabled(true);
        }
    }

    public void exibirTabelas(List tabelas) throws GeradorMVCException {
        try {
            this.tabelas = tabelas;
            int i = 0;
            Iterator resultado = tabelas.iterator();
            System.out.print("chegou aqui");
            this.cbTabelas.removeAllItems();
            while (resultado.hasNext()) {
                this.cbTabelas.addItem(tabelas.get(i));
                resultado.next();
                i++;
                System.out.print("chegou aqui tamém");
            }
        } finally {
            cbTabelas.setEnabled(true);
        }
    }

    public void exibirColunasTabela(List colunasTabela) {
        this.colunasTabela = colunasTabela;

        DefaultTableModel model = (DefaultTableModel) tblColunasTabela.getModel();
        this.removerLinhasDaTabela(model);

        Iterator resultado = colunasTabela.iterator();

        while (resultado.hasNext()) {
            Tabela tabela = (Tabela) resultado.next();
            Boolean selecionar = tabela.isSelecionar();
            String tipoObjeto = tabela.getTipoObjeto();
            String nomeColuna = tabela.getNomeColuna();
            String tipoColuna = tabela.getTipoColuna();
            Boolean nulo = tabela.isNulo();
            System.out.println(tipoObjeto);

            Object[] linha = {selecionar, tipoObjeto, nomeColuna, tipoColuna, nulo};
            model.addRow(linha);
        }
    }

    public void exibirColunasSelecionadas() {
        DefaultTableModel modelSelecionadas = (DefaultTableModel) tblColunasSelecionadas.getModel();
        DefaultTableModel model = (DefaultTableModel) tblColunasTabela.getModel();
        this.removerLinhasDaTabela(modelSelecionadas);
        int linhaTabela = 0;
        while (linhaTabela < model.getRowCount()) {
            if ((Boolean) model.getValueAt(linhaTabela, 0)) {
                String tipoObj = (String) model.getValueAt(linhaTabela, 1);
                String nomeColuna = (String) model.getValueAt(linhaTabela, 2);
                String tipoColuna = (String) model.getValueAt(linhaTabela, 3);
                String nomeAtributo = (String) model.getValueAt(linhaTabela, 2);
                String tipoAtributo = (String) model.getValueAt(linhaTabela, 3);
                Boolean inserir = true;
                Boolean alterar = true;

                Object[] linha = {tipoObj, nomeColuna, tipoColuna, nomeAtributo, tipoAtributo, inserir, alterar};
                modelSelecionadas.addRow(linha);
            }
            linhaTabela++;
        }
    }

    public void setParametrosDB(Principal principal) {
        ParametrosDB.setDriver(principal.getDriver());
        ParametrosDB.setUrl(principal.getURL());
        ParametrosDB.setUser(principal.getUsuario());
        ParametrosDB.setPassword(principal.getSenha());
    }

    public Principal getDadosConexao() throws GeradorMVCException {
        Principal principal = new Principal();
        principal.setDriver((String) cbDriver.getSelectedItem());
        if (cbDatabase.isEnabled()) {
            principal.setURL(edtURL.getText() + "/" + cbDatabase.getSelectedItem());
        } else {
            principal.setURL(edtURL.getText());
        }
        principal.setUsuario(edtUsuario.getText());
        principal.setSenha(edtSenha.getText());
        return principal;
    }

    public String getTabela() throws GeradorMVCException {
        String nometabela = (String) cbTabelas.getSelectedItem();
        return nometabela;
    }

    public void btnTestarConexaoAddActionListener(ActionListener ouvinte) {
        btnTestarConexao.addActionListener(ouvinte);
    }

    public void btnConectarDatabaseAddActionListener(ActionListener ouvinte) {
        btnConectarDatabase.addActionListener(ouvinte);
    }

    public void btnLimparDadosAddActionListener(ActionListener ouvinte) {
        btnLimparDados.addActionListener(ouvinte);
    }

    public void btnListarColunasTabelaAddActionListener(ActionListener ouvinte) {
        btnListarCampos.addActionListener(ouvinte);
    }

    public void limpaDadosConexao() {
        edtURL.setText(null);
        edtUsuario.setText(null);
        edtSenha.setText(null);
        cbDatabase.setEnabled(false);
        cbTabelas.setEnabled(false);
        btnConectarDatabase.setEnabled(false);
    }

    private void removerLinhasDaTabela(DefaultTableModel model) {
        while (model.getRowCount() > 0) {
            int ultimaLinha = model.getRowCount() - 1;
            model.removeRow(ultimaLinha);
        }
    }

    private List getColunasSelecionadas(DefaultTableModel model) {
        while (model.getRowCount() > 0) {
            int ultimaLinha = model.getRowCount() - 1;
            if ((Boolean) model.getValueAt(ultimaLinha, 1)) {
                System.out.print("Teste");
            }
        }

        return this.colunasSelecionadas;
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUIPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAjuda;
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConectarDatabase;
    private javax.swing.JButton btnFinalizar;
    private javax.swing.JButton btnLimparDados;
    private javax.swing.JButton btnListarCampos;
    private javax.swing.JButton btnProximo;
    private javax.swing.JButton btnTestarConexao;
    private javax.swing.JComboBox cbDatabase;
    private javax.swing.JComboBox cbDriver;
    private javax.swing.JComboBox cbTabelas;
    private javax.swing.JSeparator divButton;
    private javax.swing.JSeparator divTop;
    private javax.swing.JTextField edtArquivoDeConfiguracao;
    private javax.swing.JTextField edtNomeDaClasse;
    private javax.swing.JTextField edtNomeDoProjeto;
    private javax.swing.JPasswordField edtSenha;
    private javax.swing.JTextField edtURL;
    private javax.swing.JTextField edtUsuario;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel lblArquivoDeConfiguracao;
    private javax.swing.JLabel lblDataBase;
    private javax.swing.JLabel lblDriver;
    private javax.swing.JLabel lblNomeDaClasse;
    private javax.swing.JLabel lblNomeDoProjeto;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblTabelas;
    private javax.swing.JLabel lblURL;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JPanel pnlBotoes;
    private javax.swing.JPanel pnlImagem;
    private javax.swing.JPanel pnlPasso1;
    private javax.swing.JPanel pnlPasso2;
    private javax.swing.JPanel pnlPasso3;
    private javax.swing.JPanel pnlPasso4;
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JTable tblColunasSelecionadas;
    private javax.swing.JTable tblColunasTabela;
    // End of variables declaration//GEN-END:variables
    private List databases;
    private List tabelas;
    private List colunasTabela;
    private List colunasSelecionadas;
}
